<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>全站日志查看</title>
    <header th:replace="header::html"></header>
</head>

<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a><cite>首页</cite></a>
            <a><cite>系统管理</cite></a>
            <a><cite>需求列表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>

<div class="layui-fluid">
    <div class="layui-row  layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form  layui-col-space5">

                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="logDescribe" placeholder="请输入日志内容关键字" autocomplete="off"
                                   class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                            <select name="operationType" lay-filter="operationType">
                                <option value="">请选择日志操作类型</option>
                                <option value="select">select</option>
                                <option value="delete">delete</option>
                                <option value="update">update</option>
                                <option value="insert">insert</option>
                            </select>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="test20" placeholder="请选择开始日期"
                                       name="startDate">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="test21" placeholder="请选择结束日期" name="endDate">
                            </div>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search"><i
                                    class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>


                <div class="layui-card-body ">
                    <table class="layui-hide" id="log" lay-filter="log"></table>
                </div>

                <div class="layui-card-body ">
                    <script type="text/html" id="barDemo">
                        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"
                        >删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#test20'
			, done: function (value, date) {
				//layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});

		laydate.render({
			elem: '#test21'
			, done: function (value, date) {
				//layer.alert('你选择的日期是：' + value + '<br>获得的对象是' + JSON.stringify(date));
			}
		});
	});


	layui.use('table', function () {
		var table = layui.table,
			form = layui.form;
		table.render({
			elem: '#log'
			, url: '/api-back/log/list' //数据接口
			, page: true //开启分页
			, cellMinWidth: 80 //全局定义常规单元格的最小宽度
			, response: {
				dataName: 'datas' //规定数据列表的字段名称，默认：data
			}
			, cols: [
				[ //表头
					{type: 'checkbox', fixed: 'left'},
					{title: '序号', type: 'numbers', width: '5%'}
					, {field: 'id', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
					, {field: 'userId', title: '操作者账号', align: 'center'}
					, {field: 'logDescribe', title: '日志详情', align: 'center'}
					, {field: 'logLevel', title: '日志等级', align: 'center', width: "5%"}
					, {field: 'createTime', title: '时间', align: 'center', sort: true, width: "10%"}
					, {field: 'operationType', title: '日志操作类型', align: 'center', width: "7%"}
					, {field: 'operationUnit', title: '操作单元', align: 'center', width: "5%"}
					, {field: 'method', title: '后台方法', align: 'center'}
					, {field: 'args', title: '参数个数', align: 'center', width: "5%"}
					, {field: 'runTime', title: '方法执行时间', align: 'center', width: "7%"}
					, {field: 'returnValue', title: '方法结果', align: 'center'}
					, {title: '操作', toolbar: '#barDemo', align: 'center'}
				]
			],
			done: function () {
				//checkPermission();
				$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
			}
		});

		//监听工具条
		table.on('tool(log)', function (obj) {
			var data = obj.data;//获取点击行数据
			if (obj.event === 'del') {
				layer.confirm('确认删除该条日志吗?', function (index) {
					$.ajax({
						url: "/api-back/log/delete",
						type: "GET",
						data: {id: data.id},
						dataType: 'json',
						success: function (result) {
							layer.alert("删除成功", {icon: 1}, function (index1) {
								layer.close(index1);
								//xadmin.father_reload();
								table.reload('log');
								$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
							});
						},
						error: function () {
							layer.open({
								type: 2,
								content: "/404.html",
								area: ['60%', '60%'],
								title: '权限不足'
							});
						}
					});
				});
			}
		});

		//搜索
		form.on('submit(search)', function (data) {
			var data = data.field;
			table.render({
				elem: '#log'
				, url: '/api-back/log/findLogByFuzzy' //数据接口
				, page: true //开启分页
				, where: {
					"logDescribe": data.logDescribe,
					"operationType": data.operationType,
					"startTime": data.startDate,
					"endTime": data.endDate
				}
				, response: {
					countName: 'count', //规定数据总数的字段名称，默认：count
					dataName: 'datas' //规定数据列表的字段名称，默认：data
				}
				, cols: [
					[ //表头
						{type: 'checkbox', fixed: 'left'},
						{title: '序号', type: 'numbers', width: '5%'}
						, {field: 'id', title: 'ID', align: 'center', sort: true, width: "5%", style: 'display:none;'}
						, {field: 'userId', title: '操作者账号', align: 'center'}
						, {field: 'logDescribe', title: '日志详情', align: 'center'}
						, {field: 'logLevel', title: '日志等级', align: 'center', width: "5%"}
						, {field: 'createTime', title: '时间', align: 'center', sort: true, width: "10%"}
						, {field: 'operationType', title: '日志操作类型', align: 'center', width: "7%"}
						, {field: 'operationUnit', title: '操作单元', align: 'center', width: "5%"}
						, {field: 'method', title: '后台方法', align: 'center'}
						, {field: 'args', title: '参数个数', align: 'center', width: "5%"}
						, {field: 'runTime', title: '方法执行时间', align: 'center', width: "7%"}
						, {field: 'returnValue', title: '方法结果', align: 'center'}
						, {title: '操作', toolbar: '#barDemo', align: 'center'}
					]
				],
				done: function () {
					//checkPermission();
					$('table.layui-table thead tr th:eq(2)').addClass('layui-hide');//隐藏第一列的表头
				}
			});
			return false;
		});


	});

	function dateCompare(startDate, endDate) {
		var oDate1 = new Date(startDate);
		var oDate2 = new Date(endDate);
		if (oDate1 > oDate2) {
			console.log('第一个大');
			return false;
		} else {
			console.log('第二个大');
			return true;
		}
	}


</script>
</html>